<?php

namespace mbilling\BillingBundle\Model;

use Doctrine\ORM\EntityManager;
use mbilling\BillingBundle\Entity\domains;


Class DomainsModel
{
    protected $em;

    public function __construct(EntityManager $em)
    {
        $this->em = $em;
    }
    
    public function findAll()
    {
        $domains = $this->em->getRepository('BillingBundle:domains')->findAll();
        return $domains;
    }

    public function findByUserId($user_id)
    {
        $domains = $this->em->getRepository('BillingBundle:domains')->findBy(array('user_id' => $user_id));
        return $domains;
    }
    
    public function FindByPK($domain_id)
    {
        $domain = $this->em->find('BillingBundle:domains', $domain_id);
        return $domain;
    }

    public function findByOrderId($order_id)
    {
        $domain = $this->em->getRepository('BillingBundle:domains')->findBy(array('order_id' => $order_id));
        return $domain;
    }
    
    public function findByDomainName($domain_name)
    {
        $domain = $this->em->getRepository('BillingBundle:domains')->findOneBy(array('name' => $domain_name));
        return $domain;
    }
    
    public function findAllNotActive()
    {
        $domains = $this->em->getRepository('BillingBundle:domains')->findBy(array('is_active' => "0"));
        return $domains;
    }
    
    public function create($oEntity)
    {    
        $this->em->persist($oEntity);
        $this->em->flush();
    }
    
    public function removeByPK($domain_id)
    {
        $domain = $this->em->find('BillingBundle:domains', $domain_id);
        $this->em->remove($domain);
        $this->em->flush();
    }

    public function checkDomain($name)
    {
        $domain = $this->em->getRepository('BillingBundle:domains')->findOneBy(array('name' => $name));
        if (isset($domain))
            return true;
        else
            return false;
    }
}
?>
